package com.example.demo.commons.result.common.entity;


import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p> ID分页对象 </p>
 *
 * @author tanyunpeng
 * @date 2021/11/18
 */
@Data
@NoArgsConstructor
public class IDPageRequest implements java.io.Serializable {

    private static final long serialVersionUID = -3249240106177676069L;

    private Long firstId;

    private Long lastId;

    private Long startId;

    private Long endId;
    /**
     * 每页显示数量
     */
    private int size = 50;

    /**
     * 上一页
     */
    public IDPageRequest previous(Long firstId, int size) {
        if (size < 1) {
            throw new IllegalArgumentException("Page size must not be less than one!");
        }
        IDPageRequest request = new IDPageRequest();
        request.setLastId(firstId);
        request.setSize(size);
        return request;
    }

    /**
     * 下一页
     */
    public IDPageRequest next(Long lastId, int size) {
        if (size < 1) {
            throw new IllegalArgumentException("Page size must not be less than one!");
        }
        IDPageRequest request = new IDPageRequest();
        request.setLastId(lastId);
        request.setSize(size);
        return request;
    }

    /**
     * 第一页
     */
    public IDPageRequest first() {
        IDPageRequest request = new IDPageRequest();
        request.setSize(size);
        return request;
    }

    /**
     * 最后一页
     */
    public IDPageRequest last() {
        IDPageRequest request = new IDPageRequest();
        request.setSize(size);
        return request;
    }

    /**
     * 是否第一页
     */
    public boolean isFirstPage() {
        if (firstId == null && lastId == null) {
            return true;
        }
        return true;
    }
}